<?php
class FindTextField extends CWidget {
	/*
		
		options:
			add as attribute on element
			id  : id of element 
		windowParam:
			url:
			name:
			specs:
		callback:
		beforePopupFunc:
		afterPopupFunc:
	*/
	
	public $options;
	public $windowParams;
	public $windowSpecs ="";
	public $callback="";
	public $formId="";
	public $beforePopupFunc="";
	public $afterPopupFunc="";
	
	private $defOptions = array(
		"id"=>"",
		"value" => "",
		"onClick" =>"");
	
	private $defWindowParams = array(
		"url"=>"",
		"name"=>"_blank",
		"specs"=>array(
			"menubar" =>"no",
			"resizeable"=>"no",
			"scrollbars"=>"no",
			"status"=>"no",
			"titlebar"=>"no",
			"toolbar"=>"no",
			"height"=>"500",
			"width"=>"500",
			"top"=>"-1",
			"left"=>"-1",			
		)
	);
		
	public function init(){
		if (!is_array($this->options)){
			$this->options = array();
		}
		
		if (!is_array($this->windowParams)){
			$this->windowParams = array("specs"=>array());
		}else{
			if (!is_array($this->windowParams["specs"])){
				$this->windowParams["specs"] = array();
			}
		}	
		$this->options = array_merge($this->defOptions,$this->options);		
		$this->windowParams["specs"] = array_merge($this->defWindowParams["specs"],$this->windowParams["specs"]);
		$this->windowParams = array_merge($this->defWindowParams,$this->windowParams);
		
		//specs to string
		$specsKey = array_keys($this->windowParams["specs"]);		
		foreach ($specsKey as $specKey){
			if ($specKey == "left"){
				if ($this->windowParams["specs"]["left"] == -1){
					continue;
				}
			}
			
			if ($specKey == "top"){
				if ($this->windowParams["specs"]["top"] == -1){
					continue;
				}
			}			
			$this->windowSpecs .= $specKey . "=". $this->windowParams["specs"][$specKey] .",";
		}
		
	}
	
    public function run() {
		$this->render('findTextField');
    }
}
?>